package com.uzhie.jt808;

import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

/**
 * Created by TangFei on 2018/7/30.
 * 808 本地缓存 用于获取流水号和缓存备用数据
 */
public class JT808SysCache<K, V> {

    private volatile int plaFlowNum = 0;
    private volatile ConcurrentMap<K, V> cacheMap = new ConcurrentHashMap<>();

    private JT808SysCache() {
    }

    public synchronized int getPlaFlowNum() {
        int temp = plaFlowNum;
        if (this.plaFlowNum == 0XFFFF) {
            this.plaFlowNum = 0;
        } else {
            this.plaFlowNum++;
        }
        return temp;
    }

    public ConcurrentMap<K, V> getCacheMap() {
        return cacheMap;
    }

    public synchronized void putCacheVal(K key, V val) {
        this.cacheMap.put(key, val);
    }

    public V getCacheVal(K key) {
        return this.cacheMap.get(key);
    }

    public void remove(K key) {
        this.cacheMap.remove(key);
    }
}
